package htlgkr.nodlehs;

import java.util.Hashtable;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class ColorChooser extends Activity {
	
	SeekBar redBar;
	int red = 0;
	SeekBar greenBar;
	int green = 0;
	SeekBar blueBar;
	int blue = 0;
	TextView tv;
	SeekBar lightBar;
	int color = 0;
	int light = 127;
	boolean chosen = false;
	
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.color);
		
		tv = (TextView) findViewById(R.id.textView4);
		
		redBar = (SeekBar) findViewById(R.id.seekBarRed);
		redBar.setMax(255);
		redBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
					red = progress;	
					repaintTV();
			}
		});
		greenBar = (SeekBar) findViewById(R.id.seekBarGreen);
		greenBar.setMax(255);
		greenBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				green = progress;
				repaintTV();
			}
		});
		
		blueBar = (SeekBar) findViewById(R.id.seekBarBlue);
		blueBar.setMax(255);
		blueBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				blue = progress;
				repaintTV();
			}
		});
		lightBar = (SeekBar) findViewById(R.id.seekBarLight);
		lightBar.setMax(255);
		lightBar.setProgress(127);
		lightBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
					light = progress;	
					repaintTV();
			}
		});
		
		
	}
	
	public void repaintTV(){
		Color c = new Color();
		color = c.argb(light, red, green, blue);
		tv.setBackgroundColor(color);
		tv.refreshDrawableState();
		chosen = true;
	}
	
	public void chooseColor(final View v){
		Intent i = new Intent();
		if(chosen){
			i.putExtra("COLOR", color);
			setResult(Activity.RESULT_OK, i);
			finish();
		}else{
			setResult(Activity.RESULT_CANCELED, i);
			finish();
		}
	}
	
	

}
